/**
 * 
 * 起迪科技 Copyright (c) 2014-2018 QiDi,Inc.All Rights Reserved.
 */
package cn.qidisoft.edu.hzjt.service.impl;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.qidisoft.core.common.code.QdfRespCode;
import cn.qidisoft.core.common.exception.dao.DBException;
import cn.qidisoft.core.common.log.LoggerAdapter;
import cn.qidisoft.core.common.log.LoggerAdapterFactory;
import cn.qidisoft.core.common.pagination.Page;
import cn.qidisoft.core.common.pagination.PaginationBean;
import cn.qidisoft.edu.hzjt.dao.PartyJoinApplyMapper;
import cn.qidisoft.edu.hzjt.dao.PartyJoinDevelopmentAttMapper;
import cn.qidisoft.edu.hzjt.model.PartyJoinApply;
import cn.qidisoft.edu.hzjt.service.IPartyJoinApplyService;
import cn.qidisoft.edu.hzjt.utils.LogType;
import cn.qidisoft.edu.hzjt.vo.PartyJoinApplyBean;

/**
 * 
 * 
 * @author Administrator
 * @version $Id: PartyJoinApplyServiceImpl.java, v 0.1 2018年12月24日 下午2:14:02 hhl Exp $
 */
@Service("partyJoinApplyService")
public class PartyJoinApplyServiceImpl implements IPartyJoinApplyService {

  protected static final LoggerAdapter LOGGER =
      LoggerAdapterFactory.getLogger(LogType.HZJT_LOGGER.val);

  @Autowired
  private PartyJoinApplyMapper partyJoinApplyMapper;
  @Autowired
  private PartyJoinDevelopmentAttMapper partyJoinDevelopmentAttMapper;

  @Override
  public List<PartyJoinApply> queryList(PartyJoinApply data) {
    try {
      return partyJoinApplyMapper.queryList(data);
    } catch (Exception e) {
      LOGGER.error("queryList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  @Override
  public PartyJoinApply queryByPK(PartyJoinApply data) {
    try {
      return partyJoinApplyMapper.queryByPK(data);
    } catch (Exception e) {
      LOGGER.error("queryByPK [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  @Override
  @Transactional
  public int add(PartyJoinApply data) {
    try {
      return partyJoinApplyMapper.add(data);
    } catch (Exception e) {
      LOGGER.error("add [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  @Override
  @Transactional
  public int update(PartyJoinApply data) {
    try {
      return partyJoinApplyMapper.update(data);
    } catch (Exception e) {
      LOGGER.error("update [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  @Override
  @Transactional
  public int delete(PartyJoinApply data) {
    try {
      return partyJoinApplyMapper.delete(data);
    } catch (Exception e) {
      LOGGER.error("delete [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  @Override
  public PaginationBean<PartyJoinApply> queryPageList(PartyJoinApply data, Page page) {
    try {

      int c = partyJoinApplyMapper.queryPageListcount(data);
      int totalRecords = 0;
      totalRecords = (int) c;
      PaginationBean<PartyJoinApply> pageHolder =
          new PaginationBean<PartyJoinApply>(page, totalRecords);
      List<PartyJoinApply> resultList = partyJoinApplyMapper.queryPageList(data, new RowBounds(
          (pageHolder.getCurrentPage() - 1) * pageHolder.getPageSize(), pageHolder.getPageSize()));
      pageHolder.setPageList(resultList);
      return pageHolder;
    } catch (Exception e) {
      LOGGER.error("queryPageList [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  @Override
  public int validation(PartyJoinApply data) {
    try {
      return partyJoinApplyMapper.validation(data);
    } catch (Exception e) {
      e.printStackTrace();
      return -99;
    }
  }

  @Override
  public List<PartyJoinApply> export(PartyJoinApply data) {
    try {
      return partyJoinApplyMapper.export(data);
    } catch (Exception e) {
      LOGGER.error("export [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(data, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }

  /**
   * @see cn.qidisoft.edu.hzjt.service.IPartyJoinApplyService#queryPartyJoinApplyStep(cn.qidisoft.edu.hzjt.vo.PartyJoinApplyBean)
   */
  @Override
  public PartyJoinApplyBean queryPartyJoinApplyStep(PartyJoinApplyBean partyJoinApplyBean) {
    try {
      return partyJoinApplyMapper.queryPartyJoinApplyStep(partyJoinApplyBean);
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("queryPartyJoinApplyStep [{}] error," + this.getClass().getName() + "=[{}]",
          this.getClass().getName(),
          ToStringBuilder.reflectionToString(partyJoinApplyBean, ToStringStyle.SHORT_PREFIX_STYLE));
      throw new DBException(QdfRespCode.QDF_020002.getCode(), QdfRespCode.QDF_020002.getMsg(), e);
    }
  }
}
